<?php
/**
 * Created by PhpStorm.
 * User: CS
 * Date: 2018/11/12
 * Time: 13:40
 */
//引入连库文件
require './back/conn.php';
//接收令牌
if(!isset($_GET['key'])){
    echo '非法访问！';
    header("refresh:2;url=/index1.html");
    exit;
}
$key = $_GET['key'];
$newpwd = $_POST['pwd'];
//连库修改
$sql = "UPDATE `gm_index` SET `game_pwd` = '$newpwd' WHERE `change_pwd` = '$key'";
$re = mysqli_query($con,$sql);
if($re){
    //产生新令牌
    $newkey = time() . mt_rand(1111,9999);
    //将令牌写入数据库
    $sql = "UPDATE `gm_index` SET `change_pwd` = '$newkey' WHERE `change_pwd` = '$key'";
    $re = mysqli_query($con,$sql);
    echo 1;
}else{
    echo '修改密码失败！';
}
?>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link href="/vender/tanchu/dialog.css" rel="stylesheet">
    <title>修改密码</title>
</head>
<body>
<!--加载弹窗插件-->
<script src="/vender/tanchu/mDialogMin.js"></script>
<script src="/js/jquery-3.3.1.js"></script>
<script>
    $(function ($) {
        Dialog.init('<input type="text" placeholder="新密码明文显示，请注意信息安全"  style="margin:8px 0;width:100%;padding:11px 8px;font-size:15px; border:1px solid #999;"/>',{
            title : '修改密码',
            button : {
                确定 : function(){
                    var pwd = this.querySelector('input').value;
                    if(/^[a-z0-9\_\,\.\*]{6,}$/gi.test(pwd)){
                        //ajax 提交
                        $.ajax({
                            type:'post',
                            url:'/resetpwd.php',
                            data:{'pwd':pwd},
                            success: function (msg) {
                                if(msg == 1){
                                    Dialog.init('修改成功！请妥善保管您的新密码',2000);
                                    setTimeout('location.href="/index1.html"',2000);
                                }else{
                                    Dialog.init(msg,2000);
                                }
                            }
                        });
                        Dialog.close(this);
                    }else{
                        Dialog.init('你输入的密码不符合要求！',1100);
                    };
                },
                点击关闭 : function(){
                    Dialog.init('你把我关了怎么修改密码！',{maskClick : 1});
                    // Dialog.close(this);
                }
            }
        });
    });
</script>
</body>
</html>
